﻿@using  DualControl.Application.Organizations.Dto
@using  Abp.Organizations
@*@model Abp.Application.Services.Dto.ListResultDto<OrganizationUnitDto>*@
@using X.PagedList.Mvc.Core; @*import this so we get our HTML Helper*@
@using X.PagedList; @*import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)*@

@{
    ViewData["Title"] = "组织机构";
}

<h2>组织机构</h2>


@section scripts
    {
    <environment names="Development">
        <script src="~/view-resources/Views/Organizations/Index.js" asp-append-version="true"></script>
    </environment>
    <environment names="Staging,Production">
        <script src="~/view-resources/Views/Organizations/Index.js" asp-append-version="true"></script>
    </environment>
}
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    @L("Organizations")
                </h2>
                <ul class="header-dropdown m-r--5">
                    <li class="dropdown">
                        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            <i class="material-icons">more_vert</i>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li><a id="RefreshButton" href="javascript:void(0);" class="waves-effect waves-block"><i class="material-icons">refresh</i>@L("Refresh")</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div class="body table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>编码</th>
                            <th>名称</th>
                            <th>负责人</th>
                            <th>创建时间</th>
                            <th>@L("Actions")</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var org in ViewBag.PageOfOrgsListDto)
                        {
                            long userid=0;
                            if(org.User !=null)
                            {
                                userid = org.User.Id;
                            }
                            <tr>
                                <td>@org.Code</td>
                                <td>@org.DisplayName</td>
                                <td>
                                    @if (org.User != null)
                                    {
                                        @org.User.Name;
                                    }
                                </td>
                                <td>@org.CreationTime</td>
                                <td class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                        <i class="material-icons">menu</i>
                                    </a>
  <ul class="dropdown-menu pull-right">
   <li><a href="#" class="waves-effect waves-block edit-org" data-org-id="@org.Id" data-user-id="@userid" data-toggle="modal" data-target="#OrgEditModal"><i class="material-icons">edit</i>@L("Edit")</a></li>
                                        <li><a href="#" class="waves-effect waves-block delete-org" data-org-id="@org.Id" data-org-name="@org.DisplayName"><i class="material-icons">delete_sweep</i>@L("Delete")</a></li>
                                    </ul>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <button type="button" class="btn btn-primary btn-circle waves-effect waves-circle waves-float pull-right" data-toggle="modal" data-target="#OrgCreateModal">
                    <i class="material-icons">add</i>
                </button>
            </div>
        </div>
    </div>
</div>

@Html.PagedListPager((IPagedList)ViewBag.PageOfOrgsListDto, page => Url.Action("Index", new { page }))

<div class="modal fade" id="OrgCreateModal" tabindex="-1" role="dialog" aria-labelledby="UserCreateModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    <span>新建部门</span>
                </h4>
            </div>
            <div class="modal-body">
                <form name="orgCreateForm" role="form" novalidate class="form-validation">
                    <ul class="nav nav-tabs tab-nav-right" role="tablist">
                        <li role="presentation" class="active"><a href="#create-org-details" data-toggle="tab">部门名称</a></li>
                    </ul>
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane animated fadeIn active" id="create-org-details">
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <div class="form-line">

                                            <input class="form-control" type="text" name="DisplayName" required maxlength="@OrganizationUnit.MaxDisplayNameLength" minlength="3">
                                            <label class="form-label">请输入部门名称</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
                        <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="OrgEditModal" tabindex="-1" role="dialog" aria-labelledby="OrgEditModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    <span>编辑部门信息</span>
                </h4>
            </div>
            <div class="modal-body">
                <form name="orgEditForm" role="form" novalidate class="form-validation">
        <ul class="nav nav-tabs tab-nav-right" role="tablist">
      <li role="presentation" class="active"><a href="#edit-org-details" data-toggle="tab">部门名称</a></li>
      <li role="presentation"><a href="#set-org-leader" data-toggle="tab">部门负责人</a></li>
                    </ul>
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane animated fadeIn active" id="edit-org-details">
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <div class="form-line">
                                            <input type="hidden" name="id" />
                                            <input class="form-control" type="text" name="DisplayName" required maxlength="@OrganizationUnit.MaxDisplayNameLength" minlength="3">
                                            <label class="form-label">请输入部门名称</label>
                                        </div>
                                    </div>
                                </div>
                               
                        

                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane animated fadeIn" id="set-org-leader">
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <div id="div-user" class="form-line">
                         <label class="form-label">选择部门负责人</label>
     <select name="UserId" id="UserId" title="==请选择=="></select>
                                        </div>
                                    </div>
                                </div>

                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
                        <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>
